package net.zjitc.servlet.product;

import net.zjitc.domain.Product;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProduceServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * Created by Administrator on 2017/10/25.
 */
@WebServlet(name = "EditServlet",urlPatterns = "/editServlet")
public class EditServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Product p = new Product();
        try {
            BeanUtils.populate(p,request.getParameterMap());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //更新数据
        ProductService service = new ProduceServiceImpl();
        int count = service.update(p);
        //重定向
        response.sendRedirect("/modelTest/productListServlet");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
